package com.shk.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.shk.annotation.Log4jAnnotation;
import com.shk.constant.MessageConstant;
import com.shk.entity.PageResult;
import com.shk.entity.QueryPageBean;
import com.shk.entity.Result;
import com.shk.pojo.Menu;
import com.shk.service.MenuService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/menu")
public class MenuController {
        @Reference
    private MenuService menuService;


        @RequestMapping("/add")
        @Log4jAnnotation
    public Result add(@RequestBody Menu menu){
        menuService.add(menu);
        return new Result(true, MessageConstant.ADD_MENU_SUCCESS);
        }

        @RequestMapping("/findPage")
        @Log4jAnnotation
    public Map findPage(@RequestBody QueryPageBean queryPageBean){
            PageResult page = menuService.findPage(queryPageBean.getCurrentPage(), queryPageBean.getPageSize(), queryPageBean.getQueryString());
            Map map = new HashMap<>();
            map.put("page",page);
            return map;
        }
    @RequestMapping("/delete")
    @Log4jAnnotation
    public Result delete(Integer id){
            menuService.delete(id);
            return new Result(true,MessageConstant.DELETE_MENU_sUCCESS);
    }

    @RequestMapping("/findById")
    @Log4jAnnotation
    public Result findById(Integer id){
        Menu menu = menuService.findById(id);
        return new Result(true,MessageConstant.QUERY_MENU_SUCCESS,menu);
        }
    @RequestMapping("/edit")
    @Log4jAnnotation
    public Result update(@RequestBody Menu menu){
            menuService.update(menu);
            return new Result(true,MessageConstant.EDIT_MENU_SUCCESS);
    }

    @RequestMapping("/findAll")
    @Log4jAnnotation
    public Result findAll(){
           List<Menu> data = menuService.findAll();
           return new Result(true,MessageConstant.QUERY_MENU_SUCCESS,data);
    }

}


